@echo off
@REM  --------------------------------------------------------------------------------------
@REM  CreateDocumentation.bat file
@REM
@REM  This batch file create the documentation for the Enterprise Library Extensions.
@REM  

echo.
echo =========================================================
echo   Create Documentation
echo      Creates the CHM file.
echo =========================================================
echo.

set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v4.0.30319
set solutionDir="..\Documentation\"
set buildType=Debug
set returnErrorCode=true
set pause=true
set setupDir="..\Setup"

if "%1"=="/?" goto HELP

if not Exist %solutionDir%\SandcastleHelp.shfbproj goto HELP

@REM  ----------------------------------------------------
@REM  If the first parameter is /q, do not pause
@REM  at the end of execution.
@REM  ----------------------------------------------------

if /i "%1"=="/q" (
 set pause=false
 SHIFT
)

@REM  ----------------------------------------------------
@REM  If the first or second parameter is /i, do not 
@REM  return an error code on failure.
@REM  ----------------------------------------------------

if /i "%1"=="/i" (
 set returnErrorCode=false
 SHIFT
)

@REM  ----------------------------------------------------
@REM  User can override default build type by specifiying
@REM  a parameter to batch file (e.g. BuildLibrary Debug).
@REM  ----------------------------------------------------

if not "%1"=="" set buildType=%1

@REM  ------------------------------------------------
@REM  Shorten the command prompt for making the output
@REM  easier to read.
@REM  ------------------------------------------------
set savedPrompt=%prompt%
set prompt=*$g

@ECHO ----------------------------------------
@ECHO CreateDocumentation.bat Started
@ECHO ----------------------------------------
@ECHO.

pushd %solutionDir%

call %msBuildDir%\msbuild SandcastleHelp.shfbproj /t:Rebuild /p:Configuration=%buildType%
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy documentation files
@ECHO ----------------------------------------
@ECHO.

if Exist Help\EnterpriseLibraryExtensions.chm copy /V Help\EnterpriseLibraryExtensions.chm
@if errorlevel 1 goto :error

if Exist Help RMDir Help /q /s
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO CreateDocumentation.bat Completed
@ECHO ----------------------------------------
@ECHO.

@REM  ----------------------------------------
@REM  Restore the command prompt and exit
@REM  ----------------------------------------
@goto :exit

@REM  -------------------------------------------
@REM  Handle errors
@REM
@REM  Use the following after any call to exit
@REM  and return an error code when errors occur
@REM
@REM  if errorlevel 1 goto :error	
@REM  -------------------------------------------
:error
if %returnErrorCode%==false goto exit

@ECHO An error occured in CreateDocumentation.bat - %errorLevel%
if %pause%==true PAUSE
@exit errorLevel

:HELP
echo Usage: CreateDocumentation [/q] [/i] [build type] 
echo.
echo CreateDocumentation is to be executed in the scripts directory.
echo The default build type is Debug.
echo.
echo Examples:
echo.
echo    "CreateDocumentation" - builds documentation based on debug output.
echo    "CreateDocumentation Release" - builds documentation based on release output.
echo.

@REM  ----------------------------------------
@REM  The exit label
@REM  ----------------------------------------
:exit
if %pause%==true PAUSE

popd
set pause=
set solutionDir=
set buildType=
set returnErrorCode=
set prompt=%savedPrompt%
set savedPrompt=

